package com.example;

import com.example.entity.User;

import java.sql.*;
import java.util.ArrayList;

public class TestApplication {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
        ArrayList<User> list=new ArrayList<>();
        try {
            connection= DriverManager.getConnection("");
            statement= connection.createStatement();
            resultSet=statement.executeQuery("select * from user");
            while (resultSet.next()){
                int id=resultSet.getInt(1);
                String name = resultSet.getString(2);
                int age = resultSet.getInt(3);
                list.add(new User(id,name,age));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            if (null!=resultSet){
                try {
                    resultSet.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (null!=statement){
                try {
                    statement.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (null!=connection){
                try {
                    connection.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }


    }
}
